package edu.pku.sei.act.ctrl.editpart;

import org.eclipse.gef.EditPart;
import edu.pku.sei.act.model.common.ArchiModel;
import edu.pku.sei.act.model.mote.AcceptAction;
import edu.pku.sei.act.model.mote.Action;
import edu.pku.sei.act.model.mote.ActivityFinal;
import edu.pku.sei.act.model.mote.DecisionNode;
import edu.pku.sei.act.model.mote.InitialNode;
import edu.pku.sei.act.model.mote.LIP;
import edu.pku.sei.act.model.mote.MergeNode;
import edu.pku.sei.act.model.mote.Mote;
import edu.pku.sei.act.model.mote.Data;
import edu.pku.sei.act.model.mote.MoteForPackage;
import edu.pku.sei.act.model.mote.PackageI;
import edu.pku.sei.act.model.mote.Radio;
import edu.pku.sei.act.model.mote.SendAction;
import edu.pku.sei.act.model.mote.SimpleDevice;
import edu.pku.sei.act.model.mote.Task;
import edu.pku.sei.act.model.mote.TaskEditArea;
import edu.pku.sei.act.model.mote.Timer;
import edu.pku.sei.gmp.controller.editpart.GMPDiagramEditPart;
import edu.pku.sei.gmp.controller.editpart.GMPEditPartFactory;
import edu.pku.sei.gmp.model.concept.GMPModelElement;
import edu.pku.sei.gmp.model.shape.GMPDiagram;
import edu.pku.sei.gmp.model.shape.GMPShapeElement;

public class ArchiModelEditPartFactory extends GMPEditPartFactory {

	@Override
	public EditPart createEditPart(EditPart context, Object model) {
		EditPart part = null;
		if (model instanceof GMPDiagram)
			part = new GMPDiagramEditPart((GMPDiagram) model);
		else if (model instanceof GMPShapeElement)
			part = createShapeEditPart((GMPShapeElement) model);
		if (part != null) {
			part.setModel(model);
			return part;
		} else {
			return super.createEditPart(context, model);
		}
	}

	@Override
	public EditPart createShapeEditPart(GMPShapeElement model) {
		ArchiModel m = (ArchiModel) model.getModel();
		GMPModelElement mElement = (GMPModelElement) m.shape2model(model);
		if (mElement instanceof Mote) {
			return new MoteEditPart();
		}else if(mElement instanceof Data){
			return new DataEditPart();
		}else if(mElement instanceof Radio){
			return new RadioEditPart();
		}else if (mElement instanceof Timer){
			return new TimerEditPart();
		}else if (mElement instanceof SimpleDevice){
			return new SimpleDeviceEditPart();
		}else if (mElement instanceof LIP){
			return new LIPEditPart();
		}else if (mElement instanceof Task){
			return new TaskEditPart();
		}else if (mElement instanceof PackageI){
			return new PackageEditPart();
		}else if (mElement instanceof MoteForPackage){
			return new MoteForPackageEditPart();
		}else if(mElement instanceof TaskEditArea){
			return new TaskEditAreaEditPart();
		}else if(mElement instanceof InitialNode){
			return new InitialNodeEditPart();
		}else if(mElement instanceof Action){
			return new ActionEditPart();
		}else if(mElement instanceof SendAction){
			return new SendActionEditPart();
		}else if(mElement instanceof AcceptAction){
			return new AcceptActionEditPart();
		}else if(mElement instanceof DecisionNode){
			return new DecisionNodeEditPart();
		}else if(mElement instanceof MergeNode){
			return new MergeNodeEditPart();
		}else if(mElement instanceof ActivityFinal){
			return new ActivityFinalEditPart();
		}
		else 
			return super.createShapeEditPart(model);
	}

}
